using System;
using Cinemachine;
using Game.Scripts.Animation;
using Game.Scripts.ScriptableObject;
using Game.Scripts.Service;
using UnityEngine;
using UnityEngine.Assertions;
using Zenject;

namespace Game.Scripts.Entity
{
    public static class DollyAnimationParameter
    {
        public const string DollyTrigger = "DollyTrigger";
        public const string MovingTrigger = "MovingTrigger";
    }


    [RequireComponent(typeof(CinemachineVirtualCamera), typeof(DollyEventHandler),
        typeof(Animator))]
    public class DollyCamera : MonoBehaviour
    {
        private GameService _gameService;
        private Animator animator;
        private CinemachineVirtualCamera cinemachineVirtualCamera;
        private DollyEventHandler dollyEventHandler;

        [Inject]
        public void Construct(GameService gameService)
        {
            _gameService = gameService;
        }


        private void Awake()
        {
            animator = GetComponent<Animator>();
            cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
            dollyEventHandler = GetComponent<DollyEventHandler>();
        }


        private void Start()
        {
            if (_gameService.launchOption.HasFlag(LaunchOption.IfCarMoving))
            {
                if (!_gameService.launchOption.HasFlag(LaunchOption.WithDollyTrackEnabled))
                {
                    // skip the dolly shot
                    animator.SetTrigger(DollyAnimationParameter.MovingTrigger);
                }
                else
                {
                    animator.SetTrigger(DollyAnimationParameter.DollyTrigger);
                }
            }
        }
    }
}